package com.tour.modules.web.controller.api;

import com.tour.common.utils.R;
import com.tour.modules.web.entity.TCategoryEntity;
import com.tour.modules.web.entity.TInfoEntity;
import com.tour.modules.web.service.TCategoryService;
import com.tour.modules.web.service.TInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Controller
public class TCategoryApi {

    @Autowired
    private TCategoryService tCategoryService;
    @Autowired
    private TInfoService TInfoService;

    @RequestMapping("/api/category/list")
    @ResponseBody
    public R list(){
        List<TCategoryEntity> tCategoryList = tCategoryService.queryList(new HashMap<String, Object>());
        return R.ok().put("categoryList", tCategoryList);
    }
    @RequestMapping("/api/category/info")
    public String info(HttpServletRequest request){
        TCategoryEntity tCategory = tCategoryService.queryObject(Long.parseLong(request.getParameter("id")));
        if(tCategory==null){
            return null;
        }
        request.getSession().setAttribute("category",tCategory);
        return "redirect:/front/category.jsp";
    }
    //通过类型id查询景点信息
    @RequestMapping("/api/category/getInfoList")
    @ResponseBody
    public R getInfolist(HttpServletRequest request){
        Long tCategoryId=Long.parseLong(request.getParameter("id"));
        List<TInfoEntity> tInfoEntityList= TInfoService.queryListByCategory(tCategoryId);
        return R.ok().put("InfoList",tInfoEntityList);
    }

}
